package com.fzg.common.demo.readWriteTxt;

import lombok.extern.slf4j.Slf4j;

import java.io.*;
import java.util.ArrayList;

/**
 * create by fzg
 * 2022/11/17 15:16
 */

@Slf4j
public class ReadeTxtFile {

    public static void main(String[] args) {
        read();
    }

    public static void read(){
        String fileUrl = "E:\\学习\\项目\\vue-vant-app\\myBlog\\myCaveolae_server\\src\\main\\java\\com\\fzg\\common\\demo\\readWriteTxt\\demo01.txt";
        File file = new File(fileUrl);
        if (file.exists()){
            ArrayList<String> arr = new ArrayList<>();
            BufferedReader br = null;
            try {
                br = new BufferedReader(new FileReader(file));
                String info;
                while ((info = br.readLine()) != null){
                    arr.add(info);
                }
            } catch (FileNotFoundException e) {
                e.printStackTrace();
                System.out.println("文件不存在");
            } catch (IOException e){
                e.printStackTrace();
                System.out.println("文件读取失败");
            }finally {
                try {
                    br.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            log.info(arr.toString());
        }else {
            log.info("文件不存在");
        }
    }

}
